// import http from '@/utils/http'
import filter from '~@/utils/filter';
import { mapState } from 'pinia';
import { useUserStore } from '~@/stores/user';

export default {
  data() {
    return {
      imageRoot: '/',
      filter,
      searchData: {},
      loadPath: '',
    }
  },
  computed: mapState(useUserStore, ['userInfo']),
  methods: {
    fetch(path: string = '', querys: object) {
      return useGet(path || this.loadPath, querys).then((data: any) => {
        this.loadData(data)
      }).catch(() => {
      })
    },
    reload() {
      return useGet(this.loadPath, { ...this.searchData, page: this.page }).then((data : any) => {
      }).catch(() => {
      })
    },
    frush() {
      return useGet(this.loadPath, this.searchData).then((data : any) => {
        this.loadData(data)
      }).catch(e => {
      })
    },
    loadData(data : any) {
      Object.assign(this, data)
    }
  }
}